from ldap import ldapobject

# 连接到LDAP服务器
l = ldapobject.LDAPObject('ldap://your_ldap_server:port')

# 搜索特定条件（比如基于用户名查找）
baseDN = "ou=People,dc=example,dc=com"
filterstr = "(uid=your_username)"
scope = ldap.SCOPE_SUBTREE
attrs = ["cn", "mail"]

result_id = l.search(baseDN, scope, filterstr, attrs)
while 1:
    result_type, result_data = l.result(result_id, 0)
    if (result_data == []):
        break
    for entry in result_data:
        print(entry)

l.unbind_s()